package com.example.tse.rbhttpservice.service.member;


import android.content.Context;

import com.example.tse.rbhttpservice.service.HttpService;
import com.example.tse.rbhttpservice.service.RemoteServiceListenerT;
import com.example.tse.rbhttpservice.service.ResponseServiceListenerT;
import com.example.tse.rbhttpservice.service.RudderResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberSurveyGetRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberSurveyGetResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberSurveySubmitRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberSurveySubmitResponse;
import com.google.gson.Gson;

import org.kymjs.kjframe.http.HttpParams;





/**
 * 
 * @author wliu
 *    edi  tse
 */
public class MemberSurveyServiceImpl implements MemberSurveyService {
	private Context context;
	private static Gson gson = new Gson();
	
	
	public MemberSurveyServiceImpl(Context context) {
		this.context = context;
	}
	/**
	 * 获取小调研问卷内容，仅获取一条有效调研问卷
	 * @param request
	 * @param listener
	 * @return MemberSurveyGetResponse
	 */		
	 
	    public void get(MemberSurveyGetRequest request, final RemoteServiceListenerT<MemberSurveyGetResponse> listener) {

        final HttpParams params = new HttpParams();
        


        final String url = "member/survey/get";


            new HttpService().get(context, url, params, MemberSurveyGetResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberSurveyGetResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberSurveyGetResponse() : (MemberSurveyGetResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberSurveyGetResponse() : (MemberSurveyGetResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }
        });
    }

   
	
	
	/**
	 * 提交小调研问卷，题目＋答案是一一对应，有多条
	 * @param request
	 * @param listener
	 * @return MemberSurveySubmitResponse
	 */		
	 
	    public void submit(MemberSurveySubmitRequest request, final RemoteServiceListenerT<MemberSurveySubmitResponse> listener) {

        final HttpParams params = new HttpParams();
        

            params.put("surveyId",request.getSurveyId());
            params.put("topicIds",request.getTopicIds());
            params.put("answers",request.getAnswers());

        final String url = "member/survey/submit";


            new HttpService().post(context, url, params, MemberSurveySubmitResponse.class, new ResponseServiceListenerT<RudderResponse>() {

            @Override
            public void onPreStart() {
                super.onPreStart();
                listener.PreStart();
            }

            public void ok(RudderResponse rudderResponse) {
                super.ok(rudderResponse);
                listener.ok((MemberSurveySubmitResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse) {
                super.okData(rudderResponse);
                listener.okData(rudderResponse == null ? new MemberSurveySubmitResponse() : (MemberSurveySubmitResponse) rudderResponse);
            }

            @Override
            public void okData(RudderResponse rudderResponse, int fromWhere) {
                super.okData(rudderResponse, fromWhere);
                listener.okData(rudderResponse == null ? new MemberSurveySubmitResponse() : (MemberSurveySubmitResponse) rudderResponse, fromWhere);
            }

            @Override
            public void onFailure(int errorNo, String strMsg) {
                super.onFailure(errorNo, strMsg);
                listener.failue(errorNo, strMsg);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                listener.Finish();
            }
        });
    }

   
	
	
}